<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='fxsgl'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <form name="totalForm" id="totalForm" class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 80px;"><fmt:message key='sjhm'/></label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="user.mobile" value="${params.user.mobile}">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 80px;"><fmt:message key='xm'/></label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="user.realName" value="${params.user.realName}">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 80px;"><fmt:message key='zhzt'/></label>
                    <div class="layui-input-inline">
                        <select name="accountStatus">
                            <option value=""><fmt:message key='qxz'/></option>
                            <option value="1" <c:if test="${params.accountStatus == 1}">selected</c:if>><fmt:message key='zc'/></option>
                            <option value="2" <c:if test="${params.accountStatus == 2}">selected</c:if>><fmt:message key='jy'/></option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 80px;"><fmt:message key='dj'/></label>
                    <div class="layui-input-inline">
                        <select name="level.level">
                            <option value=""><fmt:message key='qxz'/></option>
                            <c:forEach var="item" items="${levels}">
                                <option value="${item.level}" <c:if test="${params.level.level == item.level}">selected</c:if>>${item.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 80px;"><fmt:message key='ly'/></label>
                    <div class="layui-input-inline">
                        <select name="source">
                            <option value=""><fmt:message key='qxz'/></option>
                            <option value="1" <c:if test="${params.source == 1}">selected</c:if>><fmt:message key='tg'/></option>
                            <option value="2" <c:if test="${params.source == 2}">selected</c:if>><fmt:message key='sdtj'/></option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                </div>

            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-field-box layui-form">

        <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i><fmt:message key='xzfxs'/></a>
        <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="enables"><i class="layui-icon">&#xe605;</i><fmt:message key='plqy'/></a>
        <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger" id="disables"><i class="layui-icon">&#x1006;</i><fmt:message key='pljy'/></a>
        <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="modifyLevel"><i class="layui-icon">&#xe605;</i><fmt:message key='plxgdj'/></a>
        <a href="javascript:void(0);" class="layui-btn layui-btn-sm" id="modifyFather"><i class="layui-icon">&#xe605;</i><fmt:message key='plbdyqr'/></a>
        <a href="javascript:void(0);" class="layui-btn layui-btn-sm" id="enableShops"><i class="layui-icon">&#xe605;</i><fmt:message key='plkqwd'/></a>
        <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger" id="disableShops"><i class="layui-icon">&#xe605;</i><fmt:message key='plgbwd'/></a>

        <table class="layui-table" lay-size="sm">
            <thead>
            <tr>
                <th width="5%"><input id="checkboxs" type="checkbox" lay-ignore lay-skin="primary"/></th>
                <th><fmt:message key='xh'/></th>
                <th><fmt:message key='xm'/></th>
                <th><fmt:message key='sjh'/></th>
                <th><fmt:message key='jb'/></th>
                <th><fmt:message key='kqwd'/></th>
                <th><fmt:message key='wdmc'/></th>
                <th><fmt:message key='ly'/></th>
                <th><fmt:message key='yqr'/></th>
                <th><fmt:message key='sqsj'/></th>
                <th><fmt:message key='zhzt'/></th>
                <th><fmt:message key='cz'/></th>
            </tr>
            </thead>
            <c:forEach items="${page.result}" var="item" varStatus="status">
                <tr>
                    <td><input type="checkbox" lay-ignore value="${item.id}" class="feijin-check" lay-skin="primary"/></td>
                    <td>${status.index + 1}</td>
                    <td>${item.user.realName}</td>
                    <td>${item.user.mobile}</td>
                    <td>${item.level.name}</td>
                    <td>
                        <c:if test="${!item.microShop}"><b style="color: #f00;"><fmt:message key='jy'/></b></c:if>
                        <c:if test="${item.microShop}"><b style="color: green;"><fmt:message key='qy'/></b></c:if>
                    </td>
                    <td>${item.shopName}</td>
                    <td>
                        <c:if test="${item.source == 1}"><fmt:message key='tg'/></c:if>
                        <c:if test="${item.source == 2}"><fmt:message key='sdtj'/></c:if>
                        <c:if test="${item.source == 3}"><fmt:message key='zjsq'/></c:if>
                    </td>
                    <td>${item.user.father.realName}</td>
                    <td><fmt:formatDate value="${item.createTime}" type="both"/></td>
                    <td>
                        <c:if test="${item.accountStatus == 1}"><fmt:message key='zc'/></c:if>
                        <c:if test="${item.accountStatus == 2}"><fmt:message key='jy'/></c:if>
                    </td>
                    <td>
                        <div class="layui-btn-container">

                            <c:choose>
                                <c:when test="${item.accountStatus == 1}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-disable"><fmt:message key='jy'/></a>
                                </c:when>
                                <c:otherwise>
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-enabled"><fmt:message key='qy'/></a>
                                </c:otherwise>
                            </c:choose>

                            <c:choose>
                                <c:when test="${item.microShop}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-closeShop"><fmt:message key='gbwd'/></a>
                                </c:when>
                                <c:otherwise>
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-openShop"><fmt:message key='kqwd'/></a>
                                </c:otherwise>
                            </c:choose>

                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modifyLevel" style="background: #009E94"><fmt:message key='xgdj'/></a>
                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs invitePeopleList" style="background: #007DDB"><fmt:message key='bdyqr'/></a>
                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs subordinateList" style="background: #3300aa"><fmt:message key='ckxjhy'/></a>
                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs distributorList" style="background: #af4040"><fmt:message key='ckxjfxs'/></a>

                        </div>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <jsp:include page="/commons/page.jsp" flush="true"/>
    </div>
</div>

<script>

    layui.use("layer", function () {

        var layer = layui.layer;

        //新增分销商
        $("#add").click(function () {
            layer.open({
                type: 2,
                title: "<fmt:message key='xzfxs'/>",
                content: "${web_domain}/distributor/create",
                area: ["90%", "90%"],
                btn: ["<fmt:message key='qd'/>", "<fmt:message key='qx'/>"],
                yes: function (index, layero) {
                    layero.find('iframe').contents().find("#submit").click();
                }
            });
        });



        //修改等级
        $(".feijin-modifyLevel").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                content: "${web_domain}/distributor/"+ id +"/modifyLevel",
                area: ["60%", "60%"],
                btn: ["<fmt:message key='qd'/>", "<fmt:message key='qx'/>"],
                yes: function (index, layero) {
                    layero.find('iframe').contents().find("#submit").click();
                }
            });
        });

        //查看下级会员
        $(".subordinateList").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                content: "${web_domain}/distributor/"+ id +"/subordinateList",
                area: ["90%", "90%"],
                btn: ["<fmt:message key='fh'/>"],
            });
        });

        //查看下级分销商
        $(".distributorList").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                content: "${web_domain}/distributor/"+ id +"/distributorList",
                area: ["90%", "90%"],
                btn: ["<fmt:message key='fh'/>"],
            });
        });

        //选择隶属邀请人
        $(".invitePeopleList").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                content: "${web_domain}/distributor/"+ id +"/invitePeopleList",
                area: ["80%", "80%"],
                btn: ["<fmt:message key='qd'/>", "<fmt:message key='qx'/>"],
                yes: function (index, layero) {
                    layero.find('iframe').contents().find("#submit").click();
                }
            });
        });

        //禁用
        $(".feijin-disable").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrjygfxsm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/distributor/disableAccount",
                    data: {id: id}
                });
            });
        });

        //启用
        $(".feijin-enabled").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrqyfxsm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/distributor/enableAccount",
                    data: {id: id}
                });
            });
        });

        //开启微店
        $(".feijin-openShop").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrkqwdm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/distributor/enableShop",
                    data: {id: id}
                });
            });
        });


        //关闭微店
        $(".feijin-closeShop").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrgbwdm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/distributor/disableShop",
                    data: {id: id}
                });
            });
        });


        //全选反选
        $("#checkboxs").click(function () {
            if (this.checked) {
                $(".feijin-check:checkbox").prop("checked", true);
            } else {
                $(".feijin-check:checkbox").prop("checked", false);
            }
        });


        //批量启用分销商
        $("#enables").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.confirm("<fmt:message key='qrqyxzdfxsm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/distributor/enableAccounts",
                    data: {"ids": ids.join(";")}
                });
            });
        });

        //批量禁用分销商
        $("#disables").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.confirm("<fmt:message key='qrjyxzdfxsm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/distributor/disableAccounts",
                    data: {"ids": ids.join(";")}
                });
            });
        });

        //批量启用微单
        $("#enableShops").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.confirm("<fmt:message key='qrqyxzdfxsdwdm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/distributor/enableShops",
                    data: {"ids": ids.join(";")}
                });
            });
        });

        //批量关闭微店
        $("#disableShops").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.confirm("<fmt:message key='qrgbxzdfxsdwdm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/distributor/disableShops",
                    data: {"ids": ids.join(";")}
                });
            });
        });

        //批量修改等级
        $("#modifyLevel").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.open({
                type: 2,
                content: "${web_domain}/distributor/"+ ids +"/modifyLevels",
                area: ["60%", "60%"],
                btn: ["<fmt:message key='qd'/>", "<fmt:message key='qx'/>"],
                yes: function (index, layero) {
                    layero.find('iframe').contents().find("#submit").click();
                }
            });

        });

        //批量修改邀请人
        $("#modifyFather").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.open({
                type: 2,
                content: "${web_domain}/distributor/"+ ids +"/invitePeopleLists",
                area: ["80%", "80%"],
                btn: ["<fmt:message key='qd'/>", "<fmt:message key='qx'/>"],
                yes: function (index, layero) {
                    layero.find('iframe').contents().find("#submit").click();
                }
            });

        });

    });
</script>
</body>
</fmt:bundle>
</html>
